package com.example.springboot.repository;

import java.util.List;

import com.example.springboot.bean.PageResult;
import com.example.springboot.bean.User;
import org.apache.ibatis.annotations.*;

@Mapper
public interface UserRepository {

	
	/**
	 * 插入数据
	 * @param user
	 * @return
	 */
	@Insert("insert into sb_user(phone,email, username, password,status,code)"
			+"values(#{phone},#{email}, #{username}, #{password}, #{status}, #{code})")
	public int insertUser(User user);
	
	/**
	 *插入数据获取主键 
	 */
//	/**
//	 * 用户注册，注册的时候默认状态为0：未激活，并且调用邮件服务发送激活码到邮箱
//	 * @param user
//	 */
//	@Insert("insert into sb_user(phone, email, username, password)"
//			+"values(#{phone}, #{email}, #{username}, #{password})")
//	public void register(User user);

	@Insert("insert into sb_user(phone,email, username, password,status,code)"
			+"values(#{phone},#{email}, #{username}, #{password}, #{status}, #{code})")
	@Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
	public void insertGetKey(User user);
	
	@Select("select * from sb_user where username = #{username}")
	@ResultMap("userResult")
	public User selectByUsername(@Param("username") String username);


	@Select("select * from sb_user")
	@Results(value = {
			@Result(id=true,column = "id",property = "id"),
			@Result(column = "phone",property = "phone"),
			@Result(column = "password",property = "password"),
			@Result(column = "username",property = "username"),
			@Result(column = "status",property = "status"),
			@Result(column = "code",property = "code"),
	},id="userResult")
	public List<User> findAll();

	@Select("select * from tb_user where id=#{id}")
	@ResultMap("userResult")
	public User findUserById(int id);
	
	@Delete("delete from tb_user where id=#{id}")
	public void delete(final long id);
	
	@Update("update sb_user set phone=#{phone},email=#{email},username=#{username}, password=#{password} "
			+ " where id=#{id}")
	public void update(final User user);

	PageResult findPage(Integer pageNum, Integer pageSize);

	public void dele(long ids[]);







}
